package work823;

import java.io.File;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.DatagramPacket;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.Scanner;

//4)、使用TCP协议实现客户端上传文件到服务器，服务器接收到文件将其保存到指定目录中，要求服务器可以处理多个客户端上传请求？字节流
public class work4Client {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    System.out.println("请输入文件路径");
    String str = sc.next();
    File f = new File(str);
    Socket socket = null;
    if (!f.isFile()){
      System.out.println("请输入正确的文件路径");
    }else {
      InetAddress ia = null;
      try {
        socket = new Socket("localhost",8888);
        OutputStream os = socket.getOutputStream();
        InputStream is = socket.getInputStream();
        os.write(str.getBytes());
        socket.shutdownOutput();
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }
}
